import pymysql
class sql():
    def __init__(self,host):
        self.con=pymysql.connect(host=host,user='root',password='yidong666',database='a3mall')
        self.cur=self.con.cursor()
    def cx(self,sql):
        self.cur.execute(sql)
        return self.cur.fetchall()
    def delete(self, sql):
        """执行删除SQL语句"""
        try:
            self.cur.execute(sql)
            self.con.commit()  # 提交事务
            return self.cur.rowcount  # 返回受影响的行数
        except Exception as e:
            self.con.rollback()  # 回滚事务
            print(f"删除失败: {e}")
            return 0
    def tc(self):
        self.cur.close()
        self.con.close()